#define  _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>


typedef struct ListNode;
  struct ListNode {
      int val;
     struct ListNode *next;
  };
  typedef struct ListNode ListNode;

struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    int a = 0;
    int b = 0;
    ListNode* p1 = headA;
    ListNode* p2 = headB;
    while (p1)
    {
        a++;
        p1 = p1->next;
    }

    while (p2)
    {
        a++;
        p2 = p2->next;
    }
	if (p2 != p1)
	{
		return NULL;
	}
    int gab = abs(a - b);
    ListNode* longList = headA;
    ListNode* shortList = headB;
    if (b >= a)
    {
       longList = headB;
       shortList = headA;
    }
    while (gab--)
    {
        longList = longList->next;
    }
    while (longList != shortList)
    {
        longList = longList->next;
        shortList = shortList->next;

    }
    return shortList;

}
int main()
{
	ListNode* past = getIntersectionNode(headA, headB);
	return 0
}


































struct ListNode {
	int val;
	struct ListNode* next;
	ListNode(int x) : val(x), next(NULL) {}
};


struct ListNode* MidNode(struct ListNode* phead)
{
	struct ListNode* fast, * slow;
	while (fast && fast->next)
	{
		fast = fast->next->next;
		slow = slow->next;
	}
	return slow;
}
struct ListNode* reverseList(struct ListNode* phead)
{
	struct ListNode* newhead = NULL;
	struct ListNode* cur = phead;
	struct ListNode* next = cur->next;

	while (cur)
	{
		next = cur->next;
		cur->next = newhead;
		newhead = cur;
		cur = next;
	}
	return newhead;
}

class PalindromeList {
public:
	bool chkPalindrome(struct ListNode* A) {

		struct ListNode* phead = A;
		struct ListNode* mid = MidNode(phead);
		struct ListNode* newphead = reverseList(mid);
		while (phead && newphead)
		{
			if (phead->val != newphead->val)
			{
				return false;
			}

			phead = phead->next;
			newphead = newphead->next;
		}

		return true;
	}
};


